package com.yzycoc.processor;

import com.yzycoc.processor.chain.Processor;

public class ProcessEvent implements Runnable {

  private Processor.NextProcessor nextProcessor;

  private Object message;


  public ProcessEvent(Processor.NextProcessor nextProcessor, Object message) {
    this.nextProcessor = nextProcessor;
    this.message = message;
    afterInit();
  }


  public void afterInit() {

  }

  @Override
  public void run() {
    fire();
  }

  /** the event will be fired */
  public void fire() {
    try {
      nextProcessor.process(message);
    } catch (Throwable e) {
      nextProcessor.exceptionCaught(e);
    }
  }
}
